import Vue from 'vue'
import Vuex from 'vuex'
import api from '@/common/api.js'
Vue.use(Vuex)
const store = new Vuex.Store({
	state: {
		userInfo: {},
		cityInfo: {
			city: '',
			latitude: '',
			longitude: ''
		},
		manObj: {

		},
		currency: '',
		lang: ''
	},
	getters: {

	},
	mutations: {
		changeUserInfo(state, data) {
			state.userInfo = data
		},
		addCityInfo(state, data) {
			state.cityInfo = data
		},
		addManObj(state, data) {
			state.manObj = data
		},
		saveCurrency(state, data) {
			state.currency = data
		},
		saveLang(state, data) {
			state.lang = data.lang
		},
	},
	actions: {
		getuserInfo(context) {
			api.userInfo().then((res) => {
				if (res && res.code == 1) {
					console.log(res)
					context.commit("changeUserInfo", res.data)
				}
			})
		},
		changeCityInfo(context, data) {
			let datas = uni.getStorageSync('cityInfo') || '';
			context.commit('addCityInfo', datas)
		},
		changeMan(context, data) {
			context.commit('addManObj', data)
		},
		// 币种
		changecCrrency(context, data) {
			let datas = uni.getStorageSync('currency') || '';
			context.commit('saveCurrency', datas)
		},
		// 语言
		changecLang(context, data) {
			let datas = uni.getStorageSync('lang') || '';
			context.commit('saveLang', datas)
		}
	}
})

export default store